<?php
/* Created by: Ignas Janickas
 * Date: 2011-12-09
 * Class works with works
 */
class Feedback {
    var $link, $id, $data;
    
    /*
     * Constructor gets data linked with feedback id
     * @param - feedback id
     * @ptype - integer
     * 
     * Constructor creates new entry in db and gets data about it
     * @param1 - work id 
     * @ptype1 - integer
     * @param2 - quality rate
     * @ptype2 - integer
     * @param3 - speed rate
     * @ptype3 - integer
     * @param4 - coment
     * @ptype4 - string
     */
    function __construct($id, $quality = null, $speed = null, $comment = null, $uid = null) {
        require_once("db.class.php");
        include("mysql.config.php");
        $this->link = new DataBase($db_address, $db_username, $db_password, $db_db);
     
        if (($quality != null) and ($speed != null) and  ($uid != null)) {
            $this->link->query("INSERT INTO `feedbacks`() VALUES()");
            $this->id = mysql_insert_id();            
            $this->setWorkId($id);
            $this->setQuality($quality);
            $this->setSpeed($speed);
            $this->setComment($comment);
            $this->setUserId($uid);
        } else {
            $this->id = $id;
        }//if $catid and $desc <> null
        
        $this->update(); //sets $data.
    }//construct
    
    /*
     * Function updates $data param
     */
    private function update() {
        $this->link->select("feedbacks","*","id='$this->id'");
        $this->data = $this->link->getResult();
    }//update
    
    /*
     * Function gets feedback id
     * @return - returns feedback id
     * @rtype - integer
     */
    function getId() {
        return $this->data['id'];
    }//getId
    
    /*
     * Function gets work id
     * @return - returns work id
     * @rtype - integer
     */
    function getWorkId() {
        return $this->data['workid'];
    }//getWorkId
    
    /*
     * Function gets quality rate
     * @return - returns quality rate
     * @rtype - integer
     */
    function getQuality() {
        return $this->data['quality'];
    }//getQuality
    
    /*
     * Function gets speed rate
     * @return - returns speed rate
     * @rtype - integer
     */
    function getSpeed() {
        return $this->data['speed'];
    }//getSpeed
    
    /*
     * Function gets comment
     * @return - returns comment
     * @rtype - string
     */
    function getComment() {
        return $this->data['comment'];
    }//getComment
   
    /*
     * Function gets user id who wrote this feedback
     * @return - returns user id
     * @rtype - integer
     */
    function getUserId() {
        return $this->data['uid'];
    }//getUserId
    
    /*
     * Function sets work id
     * @param - work id
     * @ptype - integer
     * @return - 1 if set, 0 if fail
     * @rtype - boolean
     */
    function setWorkId($id) {
        $res = $this->link->query("UPDATE `feedbacks` SET `workid` = '$id' WHERE `id` = '$this->id'");
        if ($res) {
            $this->update();
            return 1;
        } else
            return 0;
    }//setWorkId
    
    /*
     * Function sets quality rate
     * @param - quality rate
     * @ptype - integer
     * @return - 1 if set, 0 if fail
     * @rtype - boolean
     */
    function setQuality($quality) {
        $res = $this->link->query("UPDATE `feedbacks` SET `quality` = '$quality' WHERE `id` = '$this->id'");
        if ($res) {
            $this->update();
            return 1;
        } else
            return 0;
    }//setQuality
    
    /*
     * Function sets speed rate
     * @param - speed rate
     * @ptype - integer
     * @return - 1 if set, 0 if fail
     * @rtype - boolean
     */
    function setSpeed($speed) {
        $res = $this->link->query("UPDATE `feedbacks` SET `speed` = '$speed' WHERE `id` = '$this->id'");
        if ($res) {
            $this->update();
            return 1;
        } else
            return 0;
    }//setSpeed
    
    /*
     * Function sets comment
     * @param - comment
     * @ptype - string
     * @return - 1 if set, 0 if fail
     * @rtype - boolean
     */
    function setComment($comm) {
        $res = $this->link->query("UPDATE `feedbacks` SET `comment` = '$comm' WHERE `id` = '$this->id'");
        if ($res) {
            $this->update();
            return 1;
        } else
            return 0;
    }//setComment
    
    /*
     * Function sets user id
     * @param - user id
     * @ptype - integer
     * @return - 1 if set, 0 if fail
     * @rtype - boolean
     */
    function setUserId($uid) {
        $res = $this->link->query("UPDATE `feedbacks` SET `uid` = '$uid' WHERE `id` = '$this->id'");
        if ($res) {
            $this->update();
            return 1;
        } else
            return 0;
    }//setUserId
    
}//class Feedback
?>
